﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ZoomSlider.xaml.cs" >
//   J. Prinz
// </copyright>
// <summary>
//   Interaktionslogik für ZoomSlider.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AutomationMLMapper.Controls
{
    using System.Windows;
    using System.Windows.Input;

    /// <summary>
    ///   Interaktionslogik für ZoomSlider.xaml
    /// </summary>
    public partial class ZoomSliderControl
    {
        #region Static Fields

        /// <summary>
        ///   Dependency Property for the ZoomValue
        /// </summary>
        public static readonly DependencyProperty ZoomValueProperty = DependencyProperty.Register(
            "ZoomValue", typeof(double), typeof(ZoomSliderControl), new PropertyMetadata(1.0));

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ZoomSliderControl"/> class. 
        /// </summary>
        public ZoomSliderControl()
        {
            this.InitializeComponent();
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///   The Value of the ZoomSlider
        /// </summary>
        public double ZoomValue
        {
            get
            {
                return (double)this.GetValue(ZoomValueProperty);
            }

            set
            {
                this.SetValue(ZoomValueProperty, value);
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Zoom in Handler.
        /// </summary>
        /// <param name="sender">
        /// The sender. 
        /// </param>
        /// <param name="e">
        /// The e. 
        /// </param>
        private void ImageZoomIn(object sender, MouseButtonEventArgs e)
        {
            if (this.SliderToZoom.Value + this.SliderToZoom.LargeChange >= this.SliderToZoom.Maximum)
            {
                this.SliderToZoom.Value = this.SliderToZoom.Maximum;
            }
            else
            {
                this.SliderToZoom.Value = this.SliderToZoom.Value + this.SliderToZoom.LargeChange;
            }
        }

        /// <summary>
        /// Zoom out Handler.
        /// </summary>
        /// <param name="sender">
        /// The sender. 
        /// </param>
        /// <param name="e">
        /// The e. 
        /// </param>
        private void ImageZoomOut(object sender, MouseButtonEventArgs e)
        {
            if (this.SliderToZoom.Value - this.SliderToZoom.LargeChange <= this.SliderToZoom.Minimum)
            {
                this.SliderToZoom.Value = this.SliderToZoom.Minimum;
            }
            else
            {
                this.SliderToZoom.Value = this.SliderToZoom.Value - this.SliderToZoom.LargeChange;
            }
        }

        /// <summary>
        /// Zoom Reset Handler sets the ZommValue back to 1.
        /// </summary>
        /// <param name="sender">
        /// The sender. 
        /// </param>
        /// <param name="e">
        /// The e. 
        /// </param>
        private void ImageZoomReset(object sender, MouseButtonEventArgs e)
        {
            this.SliderToZoom.Value = 1;
        }

        #endregion

        // Minimum="1" Maximum="10"
    }
}